package com.mp.approvalreq.servlet.component;

import com.mp.approvalreq.entity.dto.ComponentGroupDTO;
import com.mp.approvalreq.entity.vo.ComponentGroupVO;
import com.mp.approvalreq.service.SelectApprovalServicePrx;
import com.mp.approvalreq.servlet.AbstractServlet;
import com.mp.approvalreq.util.ServiceUtils;
import com.mp.user.entity.User;
import com.plusmoney.message.SuccessMsg;
import com.plusmoney.util.BeanUtils;
import com.plusmoney.util.ParameterUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * @author liuqi
 * @date 2018/9/18
 */
@WebServlet("/getComponentGroup")
public class GetComponentGroup extends AbstractServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			User user = getReqUser(req);
			
			Integer componentGroupId = ParameterUtils.getIntegerParameter(req, "componentGroupId", true);
			SelectApprovalServicePrx selectApprovalService = ServiceUtils.getSelectApprovalServicePrx();
			
			ComponentGroupDTO componentGroupDTO = selectApprovalService.getComponentGroupDTOById(user.getCompanyId(), componentGroupId);
			
			ComponentGroupVO componentGroupVO = BeanUtils.copyProperties(ComponentGroupVO.class, componentGroupDTO);
			
			printJson(resp, SuccessMsg.getDefaultMsg(componentGroupVO));
		} catch (Throwable e) {
			onThrowable(req, resp, e);
		}
	}
}
